﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO;
using System.IO.IsolatedStorage;

namespace PreferredZhiTu
{
    public partial class MainPage : PhoneApplicationPage
    {
        // 构造函数
        public MainPage()
        {
            InitializeComponent();
        }

        private void CityButton_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Views/City.xaml", UriKind.Relative));
        }
        public string city;
        private void CityButton_Loaded(object sender, RoutedEventArgs e)
        {
            CityButton.Content = "";
            using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
            {
                IsolatedStorageFileStream fs = file.OpenFile("city.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
                StreamReader sr = new StreamReader(fs);
                city = sr.ReadToEnd();
                sr.Close();
                fs.Close();
            }

            CityButton.Content = "目的地：" + city;
        }

        private void button4_Click(object sender, RoutedEventArgs e)
        {//搜索
            if (ThemeTextBox.Text == "请输入旅行的目的")
            {
                MessageBox.Show("请输入旅游主题！");                             
            }
            else
            {
                NavigationService.Navigate(new Uri("/Views/Search.xaml", UriKind.Relative));
            }

            string startDay = datePicker1.Value.ToString();
            DateTime StartTime = DateTime.Parse(startDay);
            //启程日期
            using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
            {
                IsolatedStorageFileStream fs = file.OpenFile("start.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
                StreamWriter sr = new StreamWriter(fs);
                sr.WriteLine(StartTime);
                sr.Close();
                fs.Close();
            }
            //TravelDate(StartTime);
            //返程日期
            string endDay = datePicker2.Value.ToString();
            DateTime EndTime = DateTime.Parse(endDay);
            using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
            {
                IsolatedStorageFileStream fs = file.OpenFile("end.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
                StreamWriter sr = new StreamWriter(fs);
                sr.WriteLine(EndTime);
                sr.Close();
                fs.Close();
            }
            //TravelDate(EndTime);

            //主题
            using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
            {
                IsolatedStorageFileStream fs = file.OpenFile("theme.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
                StreamWriter sr = new StreamWriter(fs);
                sr.WriteLine(ThemeTextBox.Text);
                sr.Close();
                fs.Close();
            }
        }

        private void ApplicationBarIconButton_Click(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri("/Views/LogIn.xaml", UriKind.Relative));
        }

        private void ApplicationBarIconButton_Click_1(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri("/Views/TuiSong.xaml", UriKind.Relative));
        }

        private void ApplicationBarIconButton_Click_2(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri("/Views/Ouser.xaml", UriKind.Relative));
        }

        private void ThemeTextBox_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            ThemeTextBox.Text = "";
        }

        private void ThemeTextBox_MouseLeave(object sender, MouseEventArgs e)
        {
            if (ThemeTextBox .Text=="")
            {
                ThemeTextBox.Text = "请输入旅行的目的";
            }
            
        }


    }
}